//版权说明：修正按钮、文本位置，版本号：3.0，生成日期：2021-12-26，作者：房晓童，内容：入侵检测器类
// 功能：入侵检测器的各成员变量与函数，与其它文件的关系：继承自Sensor.java
package com.example.safehome;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Random;

public class BreakInSensor {

    //系统状态
    private boolean systemStatus;

    //入侵地点
    private String breakInPosition;

    //是否发生入侵
    private static boolean isBreakIn = false;

    //是否运行
    private static boolean isRunning = true;

    //入侵数组
    private String[] Position = {"阳台", "客厅", "卧室1", "卧室2", "卫生间1", "卫生间2", "饭厅", "厨房"};


    BreakInSensor() {
        systemStatus = true;
        breakInPosition = "";
    }

    //监测设备运行状态
    public boolean getStatus() {
        return systemStatus;
    }
    public boolean isBreakIn() {
        return isBreakIn;
    }

    //获取案发地点
    public String getBreakInPosition() {
        return breakInPosition;
    }

    //报警
    public void ringAlarm() {
        voiceWarn();
        callPolice();
        callHost();
    }

    //鸣响驱逐警报
    public void voiceWarn() {
        return;
    }

    //通知警察
    public void callPolice() {
        java.lang.System.out.println("拨打110");
    }

    //通知用户
    public void callHost() {
    }

    //非法入侵检测是否运行
    public boolean isDetect() {
        return isRunning;
    }

    //非法入侵检测是否退出
    public boolean isQuit() {
        return !isRunning;
    }

    //运行非法入侵检测
    public void detect() {
        if (getStatus()) {
            isRunning = true;
            if (isBreakIn) {
                getBreakInPosition();
                ringAlarm();
            }
        }
    }

    //退出非法入侵检测检测
    public void quit() {
        isRunning = false;
    }

    //测试生成入侵
    public void test() {
        Random RandomPosition = new Random();
        breakInPosition = Position[RandomPosition.nextInt(Position.length - 1)];
        isBreakIn = true;
    }

    //异常处理
    public boolean exceptionHandle() {
        return true;
    }
}
